package com.ruge.user.dao;

import com.ruge.core.domain.BaseRepository;
import com.ruge.user.domain.model.IntegralLog;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Map;

/**
 * @author ruge.wu
 * @since 2022/2/11 10:52
 */
public interface IntegralLogRepository extends BaseRepository<IntegralLog> {
    @Query(value = "select aid,sum(integral) total,rank() over (order by sum(integral) desc) ranks from test.integral_log group by aid order by total desc limit :top", nativeQuery = true)
    List<Map<String, Object>> getTop(@Param("top") Integer top);

    @Query(value = "select * from ( select aid,sum(integral) total,rank() over (order by sum(integral) desc) ranks from test.integral_log group by aid order by total desc ) n where n.aid = :aid", nativeQuery = true)
    List<Map<String, Object>> getRankByAid(@Param("aid") Long aid);
}
